using UnityEngine;

public class PlayerTransformPhoton : PhotonTransformView
{
	private const int MAX_HEALTH = 100;

	private const int MAX_ARMOR = 1500;

	private const int MAX_ANGLE = 180;

	private const int MAX_CUPS = 2047;

	private const int MAX_KILLS = 127;

	private const int MAX_INCREMENT = 20;

	[SerializeField]
	private PlayerBehavior player;

	private Camera mainCamera;

	[HideInInspector]
	public bool inParom;

	[HideInInspector]
	public int parentGameObjectKey;

	[HideInInspector]
	public Transform parentGameObjectTransform;

	[HideInInspector]
	public float yCameraAngle;

	private bool prevInParom;

	private int lastSetedHealth;

	private int lastSetedArmor;

	[HideInInspector]
	public int incrementHealth;

	private int lastSetedIncrementHealth;

	public override void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
	{
		base.OnPhotonSerializeView(stream, info);
		if (player == null)
		{
			player = base.gameObject.GetComponent<PlayerBehavior>();
		}
		if (stream.isWriting)
		{
			if (mainCamera == null)
			{
				mainCamera = Camera.main;
			}
			int num = (int)mainCamera.transform.eulerAngles.x;
			if (num > 180)
			{
				num -= 360;
			}
			num += 90;
			stream.SendNext(player.maxHealth);
			DataPacker dataPacker = new DataPacker(3);
			dataPacker.PackInt(num, 180);
			dataPacker.PackBool(inParom);
			dataPacker.PackInt(parentGameObjectKey, 7);
			dataPacker.PackBool(player.jetpackShow);
			dataPacker.PackBool(player.jetpackParticleShow);
			dataPacker.PackInt(player.health, (GameController.instance.curTypeGame != TypeGame.Zombe) ? 100 : 10000);
			if (incrementHealth > 20)
			{
				incrementHealth = 0;
			}
			lastSetedHealth = player.health;
			dataPacker.PackInt(player.armor, 1500);
			lastSetedArmor = player.armor;
			dataPacker.PackInt(player.sessionCupsCount + 300, 2047);
			dataPacker.PackInt(player.Points, 127);
			dataPacker.PackBool(player.isShootingFlow);
			dataPacker.PackBool(player.currentAimMode);
			dataPacker.PackBool(player.playerReadyRace);
			dataPacker.PackBool(player.isImmortal);
			dataPacker.PackBool(player.visible);
			stream.SendNext(dataPacker.GetInt(0));
			stream.SendNext(dataPacker.GetInt(1));
			stream.SendNext(dataPacker.GetInt(2));
			stream.SendNext(incrementHealth);
			return;
		}
		player.maxHealth = (int)stream.ReceiveNext();
		DataPacker dataPacker2 = new DataPacker(new int[3]
		{
			(int)stream.ReceiveNext(),
			(int)stream.ReceiveNext(),
			(int)stream.ReceiveNext()
		});
		yCameraAngle = dataPacker2.UnPackInt(180) - 90;
		inParom = dataPacker2.UnPackBool();
		parentGameObjectKey = dataPacker2.UnPackInt(7);
		if (inParom && !prevInParom)
		{
			parentGameObjectTransform = SelfMovingObjectManager.instance.Get(parentGameObjectKey);
			player.playerParom = parentGameObjectTransform.gameObject;
			player.inParom = inParom;
			player.GetPlayerParomNavigation();
			if (player.playerParomNavigation != null)
			{
				player.playerParomNavigation.Enter(player.gameObject);
			}
		}
		else if (!inParom && prevInParom)
		{
			if (player.playerParomNavigation != null)
			{
				player.playerParomNavigation.Leave(player.gameObject);
			}
			player.inParom = inParom;
		}
		prevInParom = inParom;
		bool jetpackShow = dataPacker2.UnPackBool();
		player.jetpackShow = jetpackShow;
		jetpackShow = dataPacker2.UnPackBool();
		player.jetpackParticleShow = jetpackShow;
		bool flag = false;
		int num2 = dataPacker2.UnPackInt((GameController.instance.curTypeGame != TypeGame.Zombe) ? 100 : 10000);
		int num3 = (int)stream.ReceiveNext();
		if (num3 != lastSetedIncrementHealth || (lastSetedHealth != num2 && (num2 < player.health || (player.health == 0 && num2 >= 100))))
		{
			player.health = num2;
			lastSetedHealth = num2;
		}
		num2 = dataPacker2.UnPackInt(1500);
		if (num3 != lastSetedIncrementHealth || (lastSetedArmor != num2 && (num2 < player.armor || (player.armor == 0 && num2 >= 1500))))
		{
			player.armor = num2;
			lastSetedArmor = num2;
		}
		if (num3 != lastSetedIncrementHealth)
		{
			lastSetedIncrementHealth = num3;
		}
		num2 = dataPacker2.UnPackInt(2047) - 300;
		if (num2 != player.sessionCupsCount)
		{
			player.sessionCupsCount = num2;
		}
		num2 = dataPacker2.UnPackInt(127);
		if (num2 != player.Points)
		{
			player.Points = num2;
			if (!settings.offlineMode && GameController.instance.curTypeGame == TypeGame.normal)
			{
				player.imLeader = player.IsLeader(player);
			}
		}
		jetpackShow = dataPacker2.UnPackBool();
		if (jetpackShow != player.isShooting)
		{
			player.isShooting = jetpackShow;
			if (jetpackShow && !player.isDead)
			{
				player.weaponManager.SimpleShoot();
			}
			else
			{
				player.weaponManager.StopOnlineShoot();
			}
		}
		jetpackShow = dataPacker2.UnPackBool();
		if (jetpackShow != player.currentAimMode)
		{
			player.SwitchAimMod(jetpackShow);
		}
		jetpackShow = dataPacker2.UnPackBool();
		if (jetpackShow != player.playerReadyRace)
		{
			player.playerReadyRace = jetpackShow;
		}
		jetpackShow = dataPacker2.UnPackBool();
		player.isImmortal = jetpackShow;
		jetpackShow = dataPacker2.UnPackBool();
		if (player.visible != jetpackShow)
		{
			player.SetVisiblePlayerBesidesControl(jetpackShow);
		}
	}
}
